package cn.xiaopengstack.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author jiangyangang
 */
@Configuration
@EnableConfigurationProperties({AlipayConfigProperties.class})
public class AlipayConfig {

//    @ConditionalOnProperty(value = "alipay.enable", havingValue = "true", matchIfMissing = false)
    @Bean("alipayClient")
    public AlipayClient alipayClient(AlipayConfigProperties properties){
        return new DefaultAlipayClient(
                properties.getGatewayUrl(),
                properties.getApp_id(),
                properties.getMerchant_private_key(),
                properties.getFormat(),
                properties.getCharset(),
                properties.getAlipay_public_key(),
                properties.getSign_type()
        );
    }
}
